﻿
module("FallingZ.init")
test("FallingZ init", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    equal(5, fallingZ.center.x, "CenterX of FallingZ is set");
    equal(6, fallingZ.center.y, "CenterY of FallingZ is set");

    var relativeBody="";
    for (var i = 0; i < fallingZ._relativeBody.length; i++) {
        relativeBody += fallingZ._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(-1,0) (0,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingZ is set");

    var body= "";
    for (var i = 0; i < fallingZ.getBody.length; i++) {
        body += fallingZ.getBody[i].coordinate.toString() + " ";
    }
    equal("(4,6) (5,6) (5,7) (6,7) ", body, "CenterY of FallingZ is set");
});

test("FallingZ moveTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.moveTo(7, 8);

    deepEqual(7, fallingZ.center.x, "CenterX of FallingZ is set to new x");
    equal(8, fallingZ.center.y, "CenterY of FallingZ is set to new y");

    var relativeBody = "";
    for (var i = 0; i < fallingZ._relativeBody.length; i++) {
        relativeBody += fallingZ._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(-1,0) (0,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingZ is set");

    var body = "";
    for (var i = 0; i < fallingZ.getBody.length; i++) {
        body += fallingZ.getBody[i].coordinate.toString() + " ";
    }
    equal("(6,8) (7,8) (7,9) (8,9) ", body, "CenterY of FallingZ is set");
});

test("FallingZ moveRight", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.moveRight(); 
    deepEqual(6, fallingZ.center.x, "CenterX of FallingZ is set to x+1");
    equal(8, fallingZ.center.y, "CenterY of FallingZ is same");
});

test("FallingZ moveLeft", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.moveLeft();
    deepEqual(4, fallingZ.center.x, "CenterX of FallingZ is set to x-1");
    equal(8, fallingZ.center.y, "CenterY of FallingZ is same");
});

test("FallingZ moveUp", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.moveUp();
    equal(5, fallingZ.center.x, "CenterX of FallingZ is same");
    equal(7, fallingZ.center.y, "CenterY of FallingZ is set to y-1");
});

test("FallingZ moveDown", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.moveDown();
    equal(5, fallingZ.center.x, "CenterX of FallingZ is same");
    equal(9, fallingZ.center.y, "CenterY of FallingZ is set to y+1");
});

test("FallingZ rotate", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.rotate();
    equal(90, fallingZ.rotation, "Rotation of FallingZ is set to 90");
});

test("FallingZ rotate twice", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.rotate();
    equal(90, fallingZ.rotation, "Rotation of FallingZ is set to 90");
    fallingZ.rotate();
    equal(180, fallingZ.rotation, "Rotation of FallingZ is set to 180");
});

test("FallingZ rotateBack", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.rotateBack();
    equal(270, fallingZ.rotation, "Rotation of FallingZ is set to 270");   
});

test("FallingZ rotateTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingZ = new tetris.FallingZ(x, y, color);
    fallingZ.rotateTo(180);
    equal(180, fallingZ.rotation, "Rotation of FallingZ is set to 180");
});

